**Opening 2007 Election 
use "/Users/lewiskrashnsky/Documents/Princeton/Chris Referendum Project/Data/Ontario Data /2007 Election.dta" 

**Merging with 2007 Referendum. Results: 28,238 matches. 2,459 not matched. 
merge m:m electoraldistrictnameenglish EDVA_CODE_F using "/Users/lewiskrashnsky/Documents/Princeton/Chris Referendum Project/Data/Ontario Data /2007 Referendum.dta"

rename _merge _merge1

*Check for Duplicates
duplicates report EDVA_CODE_F
duplicates examples EDVA_CODE_F
duplicates drop

sort EDVA_CODE_F 
quietly by EDVA_CODE_F: gen dup = cond(_N==1,0,_n) 
tab dup 


***Cleaning data: Checking for odd vote totals between referendum and concurrent election in 2009***
gen weird_total = total_votes_2007-total_2007_ref_ballots
summarize weird_total 

gen weird_total_percent = (total_votes_2007-total_2007_ref_ballots)/total_votes_2007
summarize weird_total_percent

gen check_story = weird_total_percent if _merge1==3 & weird_total_percent>=.15 | weird_total_percent<=-.10
summarize check_story
sort check_story 

*Dropping the 7 observations that cannot be explained (less than .001% of observations)
drop in 1 
drop in 1 
drop in 219
drop in 578
drop in 629
drop in 631
drop in 632



**Cleaning Data: All vote total variables constructed on stata, so no coding errors to check from downloaded datasets 

**Checking for outliers 
scatter Liberal_Vote_2007 FPTP_2007_Ballot_Count 
scatter FPTP_Percent_Vote_2007 Percent_Liberal_2007 


***Analysis*** 
*Scatter plots: Liberal Voting 
graph twoway (lfit FPTP_Percent_Vote_2007 Percent_Liberal_2007) (scatter FPTP_Percent_Vote_2007 Percent_Liberal_2007)

*Scatter plots: PC Voting 
graph twoway (lfit FPTP_Percent_Vote_2007 Percent_PC_2007) (scatter FPTP_Percent_Vote_2007 Percent_PC_2007)

*Scatter plots: NDP Voting 
graph twoway (lfit FPTP_Percent_Vote_2007 Percent_NDP_2007) (scatter FPTP_Percent_Vote_2007 Percent_NDP_2007)

*Scatter plots: Green Voting 
graph twoway (lfit FPTP_Percent_Vote_2007 Percent_Green_2007) (scatter FPTP_Percent_Vote_2007 Percent_Green_2007)

*Scatter plots: Majority Party Voting (Percent Lib + PC)
gen major_party_percent_2007 = (Percent_Liberal_2007 + Percent_PC_2007) 

graph twoway (lfit FPTP_Percent_Vote_2007 major_party_percent_2007) (scatter FPTP_Percent_Vote_2007 major_party_percent_2007)


*Scatter plots: Minority Party Voting (Percent NDP + Green)
gen minor_party_percent_2007 = (Percent_NDP_2007 + Percent_Green_2007)

graph twoway (lfit FPTP_Percent_Vote_2007 minor_party_percent_2007) (scatter FPTP_Percent_Vote_2007 minor_party_percent_2007)

***Analyzing voting areas that are different percentage Conservative and Liberal**

*When PC Party % between 30-40, mean ref vote = .64 
mean FPTP_Percent_Vote_2007 if Percent_PC_2007<=.40 & Percent_PC_2007>=.30

*When PC Party % greater than 40, mean ref vote =.67 
mean FPTP_Percent_Vote_2007 if Percent_PC_2007>.40

*When PC Party % less than 30, mean ref vote = .59 
mean FPTP_Percent_Vote_2007 if Percent_PC_2007<.30

*When PC Party % less than 20, mean ref vote = .58
mean FPTP_Percent_Vote_2007 if Percent_PC_2007<.20

*When Lib % between 30-40, mean ref vote = .62 
mean FPTP_Percent_Vote_2007 if Percent_Liberal_2007<=.40 & Percent_Liberal_2007>=.30

**When Lib % over 40, mean ref vote = .62
mean FPTP_Percent_Vote_2007 if Percent_Liberal_2007>.40

**When Lib % under 30, mean ref vote = .62
mean FPTP_Percent_Vote_2007 if Percent_Liberal_2007<.30

**When Lib % under 20, mean ref vote = .63
mean FPTP_Percent_Vote_2007 if Percent_Liberal_2007<.20

****Average support among vote subsets**

mean FPTP_Percent_Vote_2007 if major_party_percent_2007>=.2 & major_party_percent_2007<=.3 

mean FPTP_Percent_Vote_2007 if major_party_percent_2007>=.4 & major_party_percent_2007<=.5 

mean FPTP_Percent_Vote_2007 if major_party_percent_2007>=.7 & major_party_percent_2007<=.8

mean FPTP_Percent_Vote_2007 if minor_party_percent_2007>=.2 & minor_party_percent_2007<=.3 

mean FPTP_Percent_Vote_2007 if minor_party_percent_2007>=.4 & minor_party_percent_2007<=.5 

mean FPTP_Percent_Vote_2007 if minor_party_percent_2007>=.7 & minor_party_percent_2007<=.8


mean MMP_Percent_Vote_2007 if major_party_percent_2007>=.2 & major_party_percent_2007<=.3 

mean MMP_Percent_Vote_2007 if major_party_percent_2007>=.4 & major_party_percent_2007<=.5 

mean MMP_Percent_Vote_2007 if major_party_percent_2007>=.7 & major_party_percent_2007<=.8



**Regression Analysis 
*Majority Party Vote Models 
regress FPTP_Percent_Vote_2007 major_party_percent_2007, robust 
outreg2 using fptp_major_2007.doc, replace ctitle (FPTP_Percentage_2007 (OLS))

*Minority Party Vote Models 
regress FPTP_Percent_Vote_2007 minor_party_percent_2007, robust 
outreg2 using fptp_minor_2007.doc, replace ctitle (FPTP_Percentage_2007 (OLS))



**New figures and regression analysis with alternative DV (MMP Vote instead of FPTP Vote)

*Creating new DV
gen MMP_Percent_Vote_2007 = MMP_2007_Ballot_Count/total_2007_ref_ballots 

**New figures 
graph twoway (lfit MMP_Percent_Vote_2007 major_party_percent_2007) (scatter MMP_Percent_Vote_2007 major_party_percent_2007)

graph twoway (lfit MMP_Percent_Vote_2007 minor_party_percent_2007) (scatter MMP_Percent_Vote_2007 minor_party_percent_2007)

*New Regression Analysis 
regress MMP_Percent_Vote_2007 major_party_percent_2007, robust 
outreg2 using mmp_major_party_2007.doc, replace ctitle (MMP Percentage 2007 (OLS)) 

 
regress MMP_Percent_Vote_2007 minor_party_percent_2007, robust 
outreg2 using mmp_minor_party_2007.doc, replace ctitle (MMP Percentage 2007 (OLS))


***Lowess Figures 
lowess MMP_Percent_Vote_2007 major_party_percent_2007

lowess MMP_Percent_Vote_2007 minor_party_percent_2007


**Trying normal transformation of data** 
gen normal_MMP_percent_vote = invnormal(MMP_Percent_Vote_2007)

gen normal_Major_Party_percent_vote = invnormal(major_party_percent_2007)

gen normal_Minor_Party_vote = invnormal(minor_party_percent_2007)

*Figures of normal transformations of data 
lowess normal_MMP_percent_vote normal_Major_Party_percent_vote

lowess normal_MMP_percent_vote normal_Minor_Party_vote


***Multivariate Regression models
regress MMP_Percent_Vote_2007 major_party_percent_2007, robust
regress MMP_Percent_Vote_2007 minor_party_percent_2007, robust

regress MMP_Percent_Vote_2007 major_party_percent_2007 minor_party_percent_2007, robust
outreg2 using Multivariate_2007_ON_Models.doc, replace ctitle (Percentage Support for Electoral Reform, 2007 ON Referendum (OLS))


**Final Models for Supplemental Material**
regress MMP_Percent_Vote_2007 major_party_percent_2007, robust 
outreg2 using Supplementary_Regression_2007_ON_Unweighted.doc, replace ctitle (MMP Percentage 2007 (OLS)) 

regress MMP_Percent_Vote_2007 major_party_percent_2007 [pweight = total_votes_2007], robust 
outreg2 using Supplementary_Regression_2007_ON_Weighted.doc, replace ctitle (MMP Percentage 2007 (OLS)) 



